<html>
<head><meta charset="utf-8"><title>REPL: Cranelift backend · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html">REPL: Cranelift backend</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="182188490"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182188490" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182188490">(Nov 29 2019 at 16:06)</a>:</h4>
<p>discussion scheduled for 17:00 GMT with <span class="user-mention" data-user-id="133247">@bjorn3</span></p>



<a name="182190940"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182190940" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182190940">(Nov 29 2019 at 16:50)</a>:</h4>
<p>I am back. No problem if you want to wait till 17:00 GMT.</p>



<a name="182190994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182190994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182190994">(Nov 29 2019 at 16:50)</a>:</h4>
<p>Context: <a href="https://github.com/rust-lang/compiler-team/issues/213#issuecomment-559055312" target="_blank" title="https://github.com/rust-lang/compiler-team/issues/213#issuecomment-559055312">https://github.com/rust-lang/compiler-team/issues/213#issuecomment-559055312</a> and following comments.</p>



<a name="182191904"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182191904" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182191904">(Nov 29 2019 at 17:06)</a>:</h4>
<p>Hi <span class="user-mention" data-user-id="133247">@bjorn3</span></p>



<a name="182191923"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182191923" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182191923">(Nov 29 2019 at 17:07)</a>:</h4>
<p>Hi</p>



<a name="182191945"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182191945" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182191945">(Nov 29 2019 at 17:07)</a>:</h4>
<p>I think the most important part is saving the user variables</p>



<a name="182192003"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192003" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192003">(Nov 29 2019 at 17:08)</a>:</h4>
<p>Right</p>



<a name="182192013"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192013" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192013">(Nov 29 2019 at 17:08)</a>:</h4>
<p>Debug-printing also to some degree</p>



<a name="182192032"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192032" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192032">(Nov 29 2019 at 17:08)</a>:</h4>
<p>One possibility for the variables is heap allocating them and telling cg_clif to look at a certain location for the locals of the main closure.</p>



<a name="182192133"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192133" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192133">(Nov 29 2019 at 17:10)</a>:</h4>
<p>Hmm</p>



<a name="182192146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192146">(Nov 29 2019 at 17:10)</a>:</h4>
<p>The <code>as_debug</code> intrinsic is easily implementable in cg_clif or any other backend I think.</p>



<a name="182192164"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192164" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192164">(Nov 29 2019 at 17:10)</a>:</h4>
<p>Oh great</p>



<a name="182192195"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192195" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192195">(Nov 29 2019 at 17:11)</a>:</h4>
<p>Ideally we don’t heap allocate, since the main point of the cranelift backend is performance.</p>



<a name="182192196"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192196" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192196">(Nov 29 2019 at 17:11)</a>:</h4>
<p>Heap allocation would also make stack pinning automatically work, as the stack variables are never moved</p>



<a name="182192201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192201">(Nov 29 2019 at 17:11)</a>:</h4>
<p>But still, there are worse things.</p>



<a name="182192209"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192209" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192209">(Nov 29 2019 at 17:11)</a>:</h4>
<p>True</p>



<a name="182192265"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192265" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192265">(Nov 29 2019 at 17:12)</a>:</h4>
<p>Is there support for stack-pinning at present?</p>



<a name="182192269"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192269" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192269">(Nov 29 2019 at 17:12)</a>:</h4>
<p>A bump allocator should work for the heap</p>



<a name="182192300"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192300" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192300">(Nov 29 2019 at 17:13)</a>:</h4>
<p>Stack-pinning should just work in cg_clif,  as it only depends on the stack not moving (why would it) and the MIR being correctly evaluated (duh)</p>



<a name="182192304"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192304" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192304">(Nov 29 2019 at 17:13)</a>:</h4>
<p>Execution would be using SpiderMonkey I presume?</p>



<a name="182192359"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192359" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192359">(Nov 29 2019 at 17:14)</a>:</h4>
<p>Yes fair</p>



<a name="182192381"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192381" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192381">(Nov 29 2019 at 17:14)</a>:</h4>
<p>Cranelift can be used as compiler backend for SpiderMonkey when compiling wasm. It doesn't depend on SpiderMonkey itself.</p>



<a name="182192384"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192384" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192384">(Nov 29 2019 at 17:14)</a>:</h4>
<p>I mean, we could run using one of several engines, but SpiderMonkey by default makes sense right?</p>



<a name="182192397"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192397" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192397">(Nov 29 2019 at 17:15)</a>:</h4>
<p>Yep of course.</p>



<a name="182192402"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192402" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192402">(Nov 29 2019 at 17:15)</a>:</h4>
<p>In cg_clif I use <a href="https://docs.rs/cranelift-simplejit/0.51.0/cranelift_simplejit/" target="_blank" title="https://docs.rs/cranelift-simplejit/0.51.0/cranelift_simplejit/"><code>simplejit</code></a> for JIT execution</p>



<a name="182192424"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192424" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192424">(Nov 29 2019 at 17:15)</a>:</h4>
<p>We want to avoid assumptions in the REPL about the execution engine I suppose.</p>



<a name="182192427"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192427" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192427">(Nov 29 2019 at 17:15)</a>:</h4>
<p>I see.</p>



<a name="182192469"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192469" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192469">(Nov 29 2019 at 17:16)</a>:</h4>
<p>Is is called "simple" as it doesn't support on stack replacement of function for deoptimization and many other things.</p>



<a name="182192748"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192748" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192748">(Nov 29 2019 at 17:20)</a>:</h4>
<p>hmm</p>



<a name="182192765"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192765" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192765">(Nov 29 2019 at 17:20)</a>:</h4>
<p>How is panicking/intrinsics::abort handled by the REPL? I assume it rolls-back all possible changes. However for example written files can't be rolled-back.</p>



<a name="182192788"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192788" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192788">(Nov 29 2019 at 17:20)</a>:</h4>
<p>I haven't worried about that until now. It's not really a concern for the MVP, though I admit more thought will need to be given to it.</p>



<a name="182192812"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192812" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192812">(Nov 29 2019 at 17:21)</a>:</h4>
<p>at the moment I <em>believe</em> it just ignores the current evaluation session.</p>



<a name="182192818"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192818" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192818">(Nov 29 2019 at 17:21)</a>:</h4>
<p>like it never happened (modulo I/O)</p>



<a name="182192821"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192821" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192821">(Nov 29 2019 at 17:21)</a>:</h4>
<p>This would be even worse for cg_clif as intrinsic::abort and SIGSEGV would kill the REPL.</p>



<a name="182192825"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192825" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192825">(Nov 29 2019 at 17:21)</a>:</h4>
<p>true</p>



<a name="182192883"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192883" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192883">(Nov 29 2019 at 17:22)</a>:</h4>
<p>BTW, what do you mean "stack replacement of function"?</p>



<a name="182192922"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192922" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192922">(Nov 29 2019 at 17:23)</a>:</h4>
<p>I am far from expert when it comes to low-level languages / bytecodes / etc.</p>



<a name="182192951"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182192951" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182192951">(Nov 29 2019 at 17:24)</a>:</h4>
<p>That the execution gets reverted back to an interpreter with all locals available to that interpreter. And when function returns the interpreter returns to the parent. I believe the other way around (interpreter -&gt; jit) is also possible.</p>



<a name="182193056"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193056" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193056">(Nov 29 2019 at 17:25)</a>:</h4>
<p>ah</p>



<a name="182193152"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193152" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193152">(Nov 29 2019 at 17:27)</a>:</h4>
<p>So, can we maybe discuss a high-level overview of how this should work?</p>



<a name="182193156"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193156" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193156">(Nov 29 2019 at 17:27)</a>:</h4>
<p>and differ from the miri backend, in particular?</p>



<a name="182193160"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193160" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193160">(Nov 29 2019 at 17:27)</a>:</h4>
<p>that would help me, I think.</p>



<a name="182193235"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193235" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193235">(Nov 29 2019 at 17:28)</a>:</h4>
<p>ok</p>



<a name="182193270"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193270" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193270">(Nov 29 2019 at 17:29)</a>:</h4>
<p>ta</p>



<a name="182193329"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193329" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193329">(Nov 29 2019 at 17:30)</a>:</h4>
<p>so, the REPL currently drives the compilation itself (doesn't really use <code>rustc_driver</code>)</p>



<a name="182193345"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193345" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193345">(Nov 29 2019 at 17:30)</a>:</h4>
<p>By the way</p>
<blockquote>
<p>This would be even worse for cg_clif as intrinsic::abort and SIGSEGV would kill the REPL.</p>
</blockquote>
<p>The <a href="https://github.com/google/evcxr" target="_blank" title="https://github.com/google/evcxr">https://github.com/google/evcxr</a> jupyter kernel decided to thrash all non serde::Serializable values on crashes.</p>



<a name="182193364"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193364" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193364">(Nov 29 2019 at 17:31)</a>:</h4>
<p>I don't know how cg_clif integrates with rustc right now (do you have to drive compilation yourself?)</p>



<a name="182193376"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193376" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193376">(Nov 29 2019 at 17:31)</a>:</h4>
<p>cg_clif uses the same interface as cg_llvm currently does</p>



<a name="182193380"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193380" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193380">(Nov 29 2019 at 17:31)</a>:</h4>
<p>but regardless, because of the way the REPL is set up, I guess I can just depend on <code>rustc_codegen_cranelift</code> an replace the normal codegen step with this.</p>



<a name="182193382"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193382" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193382">(Nov 29 2019 at 17:31)</a>:</h4>
<p>okay nice</p>



<a name="182193446"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193446" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193446">(Nov 29 2019 at 17:32)</a>:</h4>
<p>Basically: You pass -Zcodegen-backend=/path/to/librustc_codegen_cranelift.so to rustc</p>



<a name="182193450"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193450" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193450">(Nov 29 2019 at 17:32)</a>:</h4>
<p>evcxr is a nice idea, but a terrible hacky thing I believe :-) hopefully this new REPL will lend itself towards a better Jupiter kernel in time.</p>



<a name="182193455"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193455" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193455">(Nov 29 2019 at 17:32)</a>:</h4>
<p>oh right</p>



<a name="182193473"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193473" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193473">(Nov 29 2019 at 17:32)</a>:</h4>
<p>and it outputs files, necessarily, or it can output to memory too?</p>



<a name="182193481"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193481" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193481">(Nov 29 2019 at 17:32)</a>:</h4>
<p>the Cranelift bytecode</p>



<a name="182193483"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193483" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193483">(Nov 29 2019 at 17:33)</a>:</h4>
<p>Rustc then loads it, and calls <code>__rustc_codegen_backend</code>, which returns a <code>Box&lt;dyn CodegenBackend&gt;</code></p>



<a name="182193555"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193555" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193555">(Nov 29 2019 at 17:34)</a>:</h4>
<ol>
<li>Cranelift doesn't have a bytecode, only a text format.</li>
<li>When using cranelift-simplejit, the executable code gets generated on the fly into <strong>memory</strong> and a pointer to a function can then be retrieved</li>
</ol>



<a name="182193590"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193590" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193590">(Nov 29 2019 at 17:35)</a>:</h4>
<p>aha, shows me ignorance about Cranelift, sorry :-)</p>



<a name="182193602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193602">(Nov 29 2019 at 17:35)</a>:</h4>
<p>interesting</p>



<a name="182193609"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193609" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193609">(Nov 29 2019 at 17:35)</a>:</h4>
<blockquote>
<p>evcxr is a nice idea, but a terrible hacky thing I believe :-)</p>
</blockquote>
<p>Indeed. It even parses the rustc error messages.</p>



<a name="182193614"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193614" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193614">(Nov 29 2019 at 17:35)</a>:</h4>
<p>cranelift-simplejit sounds great. we should use this by default, at least (maybe the only executor for now)</p>



<a name="182193623"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193623" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193623">(Nov 29 2019 at 17:35)</a>:</h4>
<p>yep I saw that hah (error message parsing)</p>



<a name="182193685"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193685" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193685">(Nov 29 2019 at 17:36)</a>:</h4>
<blockquote>
<p>aha, shows me ignorance about Cranelift, sorry :-)</p>
</blockquote>
<p>I didn't expect you to know everything about Cranelift :)</p>



<a name="182193732"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193732" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193732">(Nov 29 2019 at 17:37)</a>:</h4>
<p>so, simplejit is somehow passed as an option for the rustc_codegen_cranelift backend?</p>



<a name="182193789"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193789" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193789">(Nov 29 2019 at 17:37)</a>:</h4>
<p>as a .so too, perhaps?</p>



<a name="182193793"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193793" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193793">(Nov 29 2019 at 17:38)</a>:</h4>
<p>Yes, you set the "SHOULD_RUN" env var: <a href="https://github.com/bjorn3/rustc_codegen_cranelift/blob/65f69d10853be9e386749b08c26abd4e84193f25/src/driver.rs#L22" target="_blank" title="https://github.com/bjorn3/rustc_codegen_cranelift/blob/65f69d10853be9e386749b08c26abd4e84193f25/src/driver.rs#L22">https://github.com/bjorn3/rustc_codegen_cranelift/blob/65f69d10853be9e386749b08c26abd4e84193f25/src/driver.rs#L22</a></p>



<a name="182193841"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193841" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193841">(Nov 29 2019 at 17:38)</a>:</h4>
<p>aha</p>



<a name="182193924"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193924" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193924">(Nov 29 2019 at 17:39)</a>:</h4>
<blockquote>
<p>cranelift-simplejit sounds great. we should use this by default, at least (maybe the only executor for now)</p>
</blockquote>
<p>Miri is nice too, as that will show you many cases of UB if you are prototyping something.</p>



<a name="182193994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182193994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182193994">(Nov 29 2019 at 17:40)</a>:</h4>
<p>And it has better fault-tolerance (rollback instead of crashing the repl)</p>



<a name="182194008"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194008" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194008">(Nov 29 2019 at 17:40)</a>:</h4>
<p>exactly my thoughts</p>



<a name="182194024"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194024" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194024">(Nov 29 2019 at 17:41)</a>:</h4>
<p>also, we may build in advanced debugging capabilities that are only possible in the miri backend.</p>



<a name="182194029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194029">(Nov 29 2019 at 17:41)</a>:</h4>
<p>but that's post-MVP obviously</p>



<a name="182194043"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194043" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194043">(Nov 29 2019 at 17:41)</a>:</h4>
<p>I have plans for various features after the MVP, like value and type holes, but I think they should be backend-independent.</p>



<a name="182194102"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194102" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194102">(Nov 29 2019 at 17:42)</a>:</h4>
<p>Yeah, priroda support would be nice. (disclaimer: I got write perm)</p>



<a name="182194112"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194112" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194112">(Nov 29 2019 at 17:42)</a>:</h4>
<p>okay nice</p>



<a name="182194118"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194118" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194118">(Nov 29 2019 at 17:42)</a>:</h4>
<p>so, the idea is, once JIT execution finishes, cg-clif can return a set of live variables? this is already possible, right?</p>



<a name="182194148"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194148" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194148">(Nov 29 2019 at 17:43)</a>:</h4>
<p>and we know their types, so we can recursively serialise all the memory they reference?</p>



<a name="182194154"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194154" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194154">(Nov 29 2019 at 17:43)</a>:</h4>
<p>How would you implement value holes in cg_clif? There may not be an invalid value for the type. (<code>MaybeUninit&lt;u8&gt;</code>)</p>



<a name="182194216"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194216" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194216">(Nov 29 2019 at 17:44)</a>:</h4>
<p>it would be done at the MIR level in fact, as I envisage, so by the time it gets to cranelift, there is nothing uninitialised, no holes, etc., until they get filled later :-)</p>



<a name="182194228"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194228" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194228">(Nov 29 2019 at 17:44)</a>:</h4>
<blockquote>
<p>so, the idea is, once JIT execution finishes, cg-clif can return a set of live variables? this is already possible, right?</p>
</blockquote>
<p>That should be on the MIR level I think.</p>



<a name="182194252"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194252" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194252">(Nov 29 2019 at 17:45)</a>:</h4>
<blockquote>
<p>and we know their types, so we can recursively serialise all the memory they reference?</p>
</blockquote>
<p>No, <em>cough</em> ptr-int casts <em>cough</em></p>



<a name="182194336"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194336" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194336">(Nov 29 2019 at 17:46)</a>:</h4>
<p>heh</p>



<a name="182194359"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194359" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194359">(Nov 29 2019 at 17:46)</a>:</h4>
<p>but wait: is the idea is the idea to keep all the memory around after JIT finishes, so serialisation isn't needed at all in theory? (sorry for my naivety)</p>



<a name="182194364"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194364" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194364">(Nov 29 2019 at 17:46)</a>:</h4>
<p>obviously we can't really do this with miri</p>



<a name="182194371"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194371" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194371">(Nov 29 2019 at 17:47)</a>:</h4>
<p>but simplejit...</p>



<a name="182194383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194383">(Nov 29 2019 at 17:47)</a>:</h4>
<blockquote>
<p>but wait: is the idea is the idea to keep all the memory around after JIT finishes, so serialisation isn't needed at all in theory? (sorry for my naivety)</p>
</blockquote>
<p>Yes, except for crash survival</p>



<a name="182194441"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194441" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194441">(Nov 29 2019 at 17:48)</a>:</h4>
<p>Except that that would need to serialize way more (c memory, open fds, memmaps, ...)</p>



<a name="182194451"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194451" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194451">(Nov 29 2019 at 17:48)</a>:</h4>
<p><code>fork()</code> should work I think</p>



<a name="182194492"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194492" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194492">(Nov 29 2019 at 17:50)</a>:</h4>
<p>yep true</p>



<a name="182194552"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194552" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194552">(Nov 29 2019 at 17:50)</a>:</h4>
<p>serialisation would also be nice to have feature-parity with using the miri backend (where you can actually save REPL sessions to disk and load them back up again later!)</p>



<a name="182194562"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194562" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194562">(Nov 29 2019 at 17:50)</a>:</h4>
<p>but maybe not an MVP thing for the Cranelift backend</p>



<a name="182194579"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194579" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194579">(Nov 29 2019 at 17:51)</a>:</h4>
<p><code>serde::Serialize</code> would be the most reliable</p>



<a name="182194663"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194663" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194663">(Nov 29 2019 at 17:52)</a>:</h4>
<p>How does the REPL handle compilation of extern crates?</p>



<a name="182194674"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194674" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194674">(Nov 29 2019 at 17:52)</a>:</h4>
<p>Would it be possible to force compilation as dylib?</p>



<a name="182194677"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194677" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194677">(Nov 29 2019 at 17:52)</a>:</h4>
<p>well, I use rustc's in-built serialisation framework right now, for obvious reasons... but I believe that is migrating over to serde anyway, at some point</p>



<a name="182194681"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194681" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194681">(Nov 29 2019 at 17:52)</a>:</h4>
<p>I've thought about that a bit</p>



<a name="182194685"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194685" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194685">(Nov 29 2019 at 17:52)</a>:</h4>
<p>but not in any depth</p>



<a name="182194703"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194703" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194703">(Nov 29 2019 at 17:53)</a>:</h4>
<p>cg_clif in jit mode can currently only load dylibs, as it doesn't link rlibs.</p>



<a name="182194714"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194714" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194714">(Nov 29 2019 at 17:53)</a>:</h4>
<p>right now it's all miri-evaluated (there's actually no explicit support for extern crates in the REPL, but in theory that's how it would work)</p>



<a name="182194716"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194716" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194716">(Nov 29 2019 at 17:53)</a>:</h4>
<p>right</p>



<a name="182194839"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194839" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194839">(Nov 29 2019 at 17:55)</a>:</h4>
<p>anyway, is there something special we need to do to tell simplejit where the memory for the previous compilation session was?</p>



<a name="182194938"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182194938" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182194938">(Nov 29 2019 at 17:57)</a>:</h4>
<p>I don't think that is necessary. Only cg_clif needs to know that to emit clif ir to load the locals from the right place.</p>



<a name="182195011"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182195011" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182195011">(Nov 29 2019 at 17:58)</a>:</h4>
<p>aha</p>



<a name="182195017"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182195017" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182195017">(Nov 29 2019 at 17:58)</a>:</h4>
<p>makes sense</p>



<a name="182195019"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182195019" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182195019">(Nov 29 2019 at 17:58)</a>:</h4>
<p>so how do we tell it?</p>



<a name="182195148"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182195148" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182195148">(Nov 29 2019 at 18:00)</a>:</h4>
<p>Given that you are already using a custom driver, it should be possible to export another function like <code>__rustc_codegen_backend</code>, but which returns a struct, whose <code>codegen_crate</code> method accepts a map between main closure locals and addresses</p>



<a name="182195151"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182195151" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182195151">(Nov 29 2019 at 18:00)</a>:</h4>
<p>Or something like that</p>



<a name="182195243"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182195243" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182195243">(Nov 29 2019 at 18:02)</a>:</h4>
<p>right, this makes sense</p>



<a name="182195339"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182195339" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182195339">(Nov 29 2019 at 18:04)</a>:</h4>
<p>so, re liveness, there's a slight issue:</p>



<a name="182195364"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182195364" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182195364">(Nov 29 2019 at 18:04)</a>:</h4>
<p>I currently compute liveness dynamically, with the miri backend</p>



<a name="182195387"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182195387" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182195387">(Nov 29 2019 at 18:04)</a>:</h4>
<p>which is less conservative than static liveness calculations</p>



<a name="182195393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182195393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182195393">(Nov 29 2019 at 18:04)</a>:</h4>
<p>obviously</p>



<a name="182195411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182195411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182195411">(Nov 29 2019 at 18:05)</a>:</h4>
<p>maybe the solution is to use static liveness for both backends, and just accept the conservativeness?</p>



<a name="182195415"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182195415" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182195415">(Nov 29 2019 at 18:05)</a>:</h4>
<p>You mean:</p>
<div class="codehilite"><pre><span></span><span class="kd">let</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">String</span>::<span class="n">new</span><span class="p">();</span><span class="w"></span>
<span class="k">if</span><span class="w"> </span><span class="n">rand_bool</span><span class="w"> </span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">drop</span><span class="p">(</span><span class="n">a</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="182195496"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182195496" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182195496">(Nov 29 2019 at 18:06)</a>:</h4>
<p>exactly</p>



<a name="182195539"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182195539" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182195539">(Nov 29 2019 at 18:07)</a>:</h4>
<p>When a variable is possibly uninitialized, it is impossible to use it. However I believe the following works:</p>
<div class="codehilite"><pre><span></span><span class="kd">let</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">String</span>::<span class="n">new</span><span class="p">();</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">String</span>::<span class="n">new</span><span class="p">();</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">c</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">rand_bool</span><span class="w"> </span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">drop</span><span class="p">(</span><span class="n">b</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="o">&amp;</span><span class="n">a</span><span class="w"></span>
<span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">drop</span><span class="p">(</span><span class="n">a</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="o">&amp;</span><span class="n">b</span><span class="w"></span>
<span class="p">};</span><span class="w"></span>
</pre></div>


<p>Which means that the possibly uninitialized variable must not be dropped yet.</p>



<a name="182195607"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182195607" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182195607">(Nov 29 2019 at 18:08)</a>:</h4>
<p>hah, I wondered what was going on there until you edited it!</p>



<a name="182195608"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182195608" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182195608">(Nov 29 2019 at 18:08)</a>:</h4>
<p>hmm</p>



<a name="182195629"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182195629" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182195629">(Nov 29 2019 at 18:09)</a>:</h4>
<p>I think just keeping all variables allocated on the heap would work.</p>



<a name="182195644"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182195644" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182195644">(Nov 29 2019 at 18:09)</a>:</h4>
<p>what's the default allocator for simplejit, a bump allocator?</p>



<a name="182195752"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182195752" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182195752">(Nov 29 2019 at 18:11)</a>:</h4>
<p>For code it just <code>mmap</code>'s. For stack, it uses the native stack. For codegened code <code>Box::new</code> it uses the same allocator as normally.</p>



<a name="182195770"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182195770" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182195770">(Nov 29 2019 at 18:11)</a>:</h4>
<p>wait, mmap's? I thought there was nothing on disk...</p>



<a name="182195820"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182195820" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182195820">(Nov 29 2019 at 18:12)</a>:</h4>
<p><code>mmap</code> can also be used for creating a large chunk of memory out of the void, not just for files.</p>



<a name="182195832"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182195832" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182195832">(Nov 29 2019 at 18:12)</a>:</h4>
<p>ah, sorry</p>



<a name="182195833"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182195833" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182195833">(Nov 29 2019 at 18:12)</a>:</h4>
<p>I see</p>



<a name="182195835"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182195835" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182195835">(Nov 29 2019 at 18:12)</a>:</h4>
<p>anyway</p>



<a name="182195845"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182195845" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182195845">(Nov 29 2019 at 18:13)</a>:</h4>
<p>I agree with you now: heap-allocating all locals just makes sense.</p>



<a name="182195858"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182195858" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182195858">(Nov 29 2019 at 18:13)</a>:</h4>
<p>I made a issue for cg_clif to do all this: <a href="https://github.com/bjorn3/rustc_codegen_cranelift/issues/817" target="_blank" title="https://github.com/bjorn3/rustc_codegen_cranelift/issues/817">https://github.com/bjorn3/rustc_codegen_cranelift/issues/817</a></p>



<a name="182195861"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182195861" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182195861">(Nov 29 2019 at 18:13)</a>:</h4>
<p>but you're thinking of using a separate allocator for that, right? a bump allocator?</p>



<a name="182195925"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182195925" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182195925">(Nov 29 2019 at 18:14)</a>:</h4>
<p>yes, if it has a measurable impact on the execution time. (even ~10ms) as a REPL has to be as fast as possible</p>



<a name="182196020"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182196020" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182196020">(Nov 29 2019 at 18:16)</a>:</h4>
<p>yep</p>



<a name="182196030"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182196030" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182196030">(Nov 29 2019 at 18:16)</a>:</h4>
<p>I will post a summary of this discussion on the issue later</p>



<a name="182196035"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182196035" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182196035">(Nov 29 2019 at 18:17)</a>:</h4>
<p>incidentally, I will probably try to optimise the miri backend anyway, but I doubt we can get any better than 100x native speed.</p>



<a name="182196041"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182196041" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182196041">(Nov 29 2019 at 18:17)</a>:</h4>
<p>which is fine for many cases (especially considering certain benefits of miri), but equally a big enough slowdown that a Cranelift backend is really worth the effort.</p>



<a name="182196044"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182196044" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182196044">(Nov 29 2019 at 18:17)</a>:</h4>
<p>okay cool. a summary would be great!</p>



<a name="182196110"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182196110" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182196110">(Nov 29 2019 at 18:18)</a>:</h4>
<p>is there anything else to discuss?</p>



<a name="182196124"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182196124" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182196124">(Nov 29 2019 at 18:19)</a>:</h4>
<p>okay, just one other thing came to mind:</p>



<a name="182196197"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182196197" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182196197">(Nov 29 2019 at 18:20)</a>:</h4>
<p>as part of this struct we could pass into <code>codegen_crate</code>, we would specify both the "user fn" locals &lt;-&gt; memory addresses mapping but also which locals should be kept live (not deallocated), which is calculated ahead of time in some MIR pass, yes?</p>



<a name="182196223"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182196223" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182196223">(Nov 29 2019 at 18:21)</a>:</h4>
<p>I think it would be the easiest to let the REPL handle all allocation and deallocation of the locals</p>



<a name="182196236"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182196236" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182196236">(Nov 29 2019 at 18:22)</a>:</h4>
<p>okay</p>



<a name="182196287"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182196287" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182196287">(Nov 29 2019 at 18:22)</a>:</h4>
<p>so the REPL would have its own bump allocator (there are already one or two crates out there for this, I believe), and just feed in the addresses?</p>



<a name="182196290"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182196290" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182196290">(Nov 29 2019 at 18:22)</a>:</h4>
<p>yes</p>



<a name="182196307"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182196307" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182196307">(Nov 29 2019 at 18:23)</a>:</h4>
<p>I will have to leave</p>



<a name="182196311"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182196311" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182196311">(Nov 29 2019 at 18:23)</a>:</h4>
<p>sorry</p>



<a name="182196312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182196312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182196312">(Nov 29 2019 at 18:23)</a>:</h4>
<p>thanks for your time</p>



<a name="182196314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182196314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182196314">(Nov 29 2019 at 18:23)</a>:</h4>
<p>it's been very useful</p>



<a name="182196328"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182196328" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182196328">(Nov 29 2019 at 18:23)</a>:</h4>
<p>no problem</p>



<a name="182196392"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182196392" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182196392">(Nov 29 2019 at 18:24)</a>:</h4>
<p><span class="user-mention" data-user-id="133247">@bjorn3</span> I guess Cranelift will have to know not to deallocate any local that's specified in that struct, and just let the caller (REPL) handle it, but that shouldn't be hard to implement I guess.</p>



<a name="182196396"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182196396" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182196396">(Nov 29 2019 at 18:24)</a>:</h4>
<p>I think we've covered all the main points</p>



<a name="182196398"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182196398" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182196398">(Nov 29 2019 at 18:24)</a>:</h4>
<p>the reset will be details as we go along</p>



<a name="182196402"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182196402" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182196402">(Nov 29 2019 at 18:24)</a>:</h4>
<p>anyway, see you later.</p>



<a name="182197313"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182197313" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182197313">(Nov 29 2019 at 18:44)</a>:</h4>
<p>yes, cg_clif shouldn't dealloc those locals</p>



<a name="182197469"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182197469" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182197469">(Nov 29 2019 at 18:48)</a>:</h4>
<p>i forgot to mention one thing: currently any jitted function will remain allocated forever and be jitted again during the next compilation round.</p>



<a name="182197512"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182197512" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182197512">(Nov 29 2019 at 18:48)</a>:</h4>
<p>i think i should teach simplejit how to dealloc specified functions and do that from cg_clif for all functions not potentially reachable from a fn ptr or vtable.</p>



<a name="182197532"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182197532" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182197532">(Nov 29 2019 at 18:49)</a>:</h4>
<p>as for the recompilation, that will need something else. maybe a static hashmap between instance hash and address?</p>



<a name="182202298"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182202298" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182202298">(Nov 29 2019 at 20:26)</a>:</h4>
<p><span class="user-mention" data-user-id="133247">@bjorn3</span> I see. the problem is, knowing whether a given fn pointer is still hanging around is not something that can be statically analysed, obviously. this would be a very hard problem to solve in the general case, I think. I'm not sure how. However, since only "new" code is sent to Cranelift (including functions), I think you'll only get this problem if the fn definition is changed. (And in that case you may want the old definition of the fn to hang around anyway, although not necessarily.)</p>



<a name="182202344"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182202344" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182202344">(Nov 29 2019 at 20:26)</a>:</h4>
<p>Still, we can be conservative and keep all versions of a fn around, throughout redefinitions.</p>



<a name="182202667"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182202667" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182202667">(Nov 29 2019 at 20:32)</a>:</h4>
<p>Actually all functions which would normally end up in a rlib are all codegened by cg_clif, even if unchanged. the incremental cache is currently not used for codegen artifacts. also for simplejit it would be impossible to use the incremental cache, as no files are written. instead it must be kept in memory.</p>



<a name="182202704"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182202704" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182202704">(Nov 29 2019 at 20:33)</a>:</h4>
<p>for fn pointer liveness i was thinking about assuming that every function which gets turned into a fnptr is assumed to be alive forever.</p>



<a name="182202724"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182202724" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182202724">(Nov 29 2019 at 20:33)</a>:</h4>
<p>the latter could work yes</p>



<a name="182202779"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182202779" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182202779">(Nov 29 2019 at 20:34)</a>:</h4>
<p>ah, I see about the incremental compilation...</p>



<a name="182202785"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182202785" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182202785">(Nov 29 2019 at 20:34)</a>:</h4>
<p>for function redefinitions, i think it is the safest to keep the old function as target of function pointers. somebody might have spawned a thread which called it. (though cg_clif doesnt yet support threads)</p>



<a name="182202871"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182202871" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182202871">(Nov 29 2019 at 20:36)</a>:</h4>
<p>this seems reasonable I think. this way only <em>new code getting evaluated</em> (current session) which <em>turns a fn into a fn-ptr</em> will make that fn stay around forever in memory</p>



<a name="182202912"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182202912" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182202912">(Nov 29 2019 at 20:37)</a>:</h4>
<p>so this will probably need to be a MIR pass in rustc itself, which is enabled only in interpreter mode. that can come down the line...</p>



<a name="182202975"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182202975" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182202975">(Nov 29 2019 at 20:39)</a>:</h4>
<p>it can also be done at the cg_clif end, which has to implement FnDef -&gt; FnPtr casts anyway.</p>



<a name="182203043"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182203043" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182203043">(Nov 29 2019 at 20:40)</a>:</h4>
<p>hmm</p>



<a name="182203080"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182203080" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182203080">(Nov 29 2019 at 20:41)</a>:</h4>
<p>maybe this makes more sense, since although checking at MIR level should be equivalent, doing it at Cranelift level is guaranteed to be more reliable, I suppose.</p>



<a name="182203833"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182203833" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182203833">(Nov 29 2019 at 20:59)</a>:</h4>
<p>Yes, and mir passes are done before monomorphization, so you may not yet know what type a vtable is created for.</p>



<a name="182204221"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182204221" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182204221">(Nov 29 2019 at 21:06)</a>:</h4>
<p>yeah fair point</p>



<a name="182204309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182204309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182204309">(Nov 29 2019 at 21:07)</a>:</h4>
<p>basically, cg-clif should take care by itself of when to deallocate functions and when not to.</p>



<a name="182204589"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182204589" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182204589">(Nov 29 2019 at 21:11)</a>:</h4>
<p>yes</p>



<a name="182204941"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182204941" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182204941">(Nov 29 2019 at 21:19)</a>:</h4>
<p>Opened <a href="https://github.com/bytecodealliance/cranelift/issues/1260" target="_blank" title="https://github.com/bytecodealliance/cranelift/issues/1260">https://github.com/bytecodealliance/cranelift/issues/1260</a> for the simpleJIT part of function dealloc.</p>



<a name="182205070"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/REPL%3A%20Cranelift%20backend/near/182205070" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/REPL.3A.20Cranelift.20backend.html#182205070">(Nov 29 2019 at 21:21)</a>:</h4>
<p>good stuff, cheers</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>